package adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;

import java.util.List;

import beans.HospitalRegisterDepartBean;
import beans.OperateGoodsDetailsBean;
import butterknife.BindView;
import custom.BaseRecyclerAdapter;
import utils.TimeUtil;

/**
 * Created by Administrator on 2018/9/14.
 */

public class ErrorGoodsAdapter extends BaseRecyclerAdapter<ErrorGoodsAdapter.ErrorGoodsViewHolder> {

    private LayoutInflater inflater;
    private List<OperateGoodsDetailsBean.DataBean> list;
    private Context mContext;

    public ErrorGoodsAdapter(Context mContext, List<OperateGoodsDetailsBean.DataBean> list) {
        inflater = LayoutInflater.from(mContext);
        this.list = list;
        this.mContext = mContext;
    }

    @Override
    public ErrorGoodsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = inflater.inflate(R.layout.adapter_error_goods, parent,false);
        ErrorGoodsViewHolder viewHolder = new ErrorGoodsViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ErrorGoodsViewHolder holder, int position) {
        OperateGoodsDetailsBean.DataBean dataBean = list.get(position);
        holder.errorGoodsName.setText(dataBean.getGoodName());
        holder.errorGoodsNumber.setText(dataBean.getSelectCabinet());
        holder.errorGoodsSize.setText(dataBean.getSpecification());
        holder.errorGoodsSupplier.setText(dataBean.getErrorRecordTime().substring(0,19));
        holder.errorGoodsCount.setText(dataBean.getNumber()+"");

        if (dataBean.getStatus() == 1) {
            holder.errorGoodsStatus.setText("未验收");
        } else if (dataBean.getStatus() == 2) {
            holder.errorGoodsStatus.setText("已验收");
        } else if (dataBean.getStatus() == 3) {
            holder.errorGoodsStatus.setText("已放入");
        } else if (dataBean.getStatus() == 4) {
            holder.errorGoodsStatus.setText("已取出");
        } else if (dataBean.getStatus() == 5) {
            holder.errorGoodsStatus.setText("已使用");
        } else if (dataBean.getStatus() == 6) {
            holder.errorGoodsStatus.setText("已退货");
        }else if (dataBean.getStatus() == 12) {
            holder.errorGoodsStatus.setText("未归审批");
        }else {
            holder.errorGoodsStatus.setText(dataBean.getStatus()+"");
        }

        if (position % 2 == 0) {
            holder.errorGoodsRl.setBackgroundColor(mContext.getResources().getColor(R.color.partLineBackground));
        } else {
            holder.errorGoodsRl.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ErrorGoodsViewHolder extends BaseRecyclerAdapter.BaseViewHolder {

        @BindView(R.id.error_goods_number)
        TextView errorGoodsNumber;
        @BindView(R.id.error_goods_name)
        TextView errorGoodsName;
        @BindView(R.id.error_goods_size)
        TextView errorGoodsSize;
        @BindView(R.id.error_goods_supplier)
        TextView errorGoodsSupplier;
        @BindView(R.id.error_goods_count)
        TextView errorGoodsCount;
        @BindView(R.id.error_goods_data_end)
        TextView errorGoodsStatus;
        @BindView(R.id.error_goods_rl)
        LinearLayout errorGoodsRl;

        public ErrorGoodsViewHolder(View itemView) {
            super(itemView);
        }
    }
}
